<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>AppEngine::XMPP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
    <script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>     
    <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'>
        <tr>
            <td class="file-title"><span class="file-title-prefix">Module</span><br />AppEngine::XMPP</td>
            <td align="right">
                <table cellspacing="0" cellpadding="2">
                    <tr valign="top">
                        <td>In:</td>
                        <td>
                            
                            <a href="../../files/lib/appengine-apis/xmpp_rb.html">lib/appengine-apis/xmpp.rb</a>
                            
                        </td>
                    </tr>
                    
                </table>
            </td>
        </tr>
    </table>
    <div id="bodyContent">
        <div id="content">
    
    <div class="description"><p>
The <a href="XMPP.html">XMPP</a> api provides an interface for accessing <a
href="XMPP.html">XMPP</a> status information, sending <a
href="XMPP.html">XMPP</a> messages, and parsing <a
href="XMPP.html">XMPP</a> responses.
</p>
</div>
    

    

    
    

    
    
    <div class="sectiontitle">Methods</div>
    <ul>
        
        <li><a href="#M000198">get_presence</a></li>
        
        <li><a href="#M000199">send_invitation</a></li>
        
        <li><a href="#M000200">send_message</a></li>
        
    </ul>
    

    

    

    
    <div class="sectiontitle">Classes and Modules</div>
    <ul>
        
        <li><span class="type">MODULE</span> <a href="XMPP/Proto.html">AppEngine::XMPP::Proto</a></li>
        
        <li><span class="type">MODULE</span> <a href="XMPP/Status.html">AppEngine::XMPP::Status</a></li>
        
        <li><span class="type">CLASS</span> <a href="XMPP/Message.html">AppEngine::XMPP::Message</a></li>
        
        <li><span class="type">CLASS</span> <a href="XMPP/Presence.html">AppEngine::XMPP::Presence</a></li>
        
        <li><span class="type">CLASS</span> <a href="XMPP/XMPPError.html">AppEngine::XMPP::XMPPError</a></li>
        
    </ul>
    

    

    

    
            <div class="sectiontitle">Class Public methods</div>
            
            <div class="method">
                <div class="title">
                    
                    <a name="M000198"></a><b>get_presence</b>(jid, from_jid=nil)
                    
                </div>
                
                <div class="description">
                  
                  <p>
Get the presence for a JID.
</p>
<p>
Args:
</p>
<ul>
<li>jid: The JID of the contact whose presence is requested.

</li>
<li>from_jid: Optional custom sender JID.

<pre>
  The default is &lt;appid&gt;@appspot.com. Custom JIDs can be of the form
  &lt;anything&gt;@&lt;appid&gt;.appspotchat.com.
</pre>
</li>
</ul>
<p>
Returns:
</p>
<ul>
<li>A <a href="XMPP/Presence.html">Presence</a> object.

</li>
</ul>

                </div>
                
                
                
                
                <div class="sourcecode">
                    <p class="source-link">
                        Source: <a href="javascript:toggleSource('M000198_source')" id="l_M000198_source">show</a>
                        
                    </p>
                    <div id="M000198_source" class="dyn-source">
                        <pre><span class="ruby-comment cmt"># File lib/appengine-apis/xmpp.rb, line 178</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_presence</span>(<span class="ruby-identifier">jid</span>, <span class="ruby-identifier">from_jid</span>=<span class="ruby-keyword kw">nil</span>)
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Jabber ID cannot be nil'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jid</span>.<span class="ruby-identifier">nil?</span>
        <span class="ruby-identifier">request</span> = <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">PresenceRequest</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">set_jid</span>(<span class="ruby-identifier">jid</span>)
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">set_from_jid</span>(<span class="ruby-identifier">from_jid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">from_jid</span>
        
        <span class="ruby-identifier">response</span> = <span class="ruby-identifier">make_sync_call</span>(<span class="ruby-value str">'GetPresence'</span>, <span class="ruby-identifier">request</span>,
                                  <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">PresenceResponse</span>)
        <span class="ruby-constant">Presence</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">isIsAvailable</span>)
      <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ApiProxy</span><span class="ruby-operator">::</span><span class="ruby-constant">ApplicationException</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span>.<span class="ruby-identifier">value_of</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">application_error</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">INVALID_JID</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid jabber ID: #{jid}&quot;</span>
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">XMPPError</span>, <span class="ruby-value str">'Unknown error retrieving presence for jabber ID: '</span> <span class="ruby-operator">+</span>
              <span class="ruby-identifier">jid</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-keyword kw">end</span></pre>
                    </div>
                </div>
                
            </div>
            
            <div class="method">
                <div class="title">
                    
                    <a name="M000199"></a><b>send_invitation</b>(jid, from_jid=nil)
                    
                </div>
                
                <div class="description">
                  
                  <p>
Send a chat invitaion.
</p>
<p>
Args:
</p>
<ul>
<li>jid: JID of the contact to invite.

</li>
<li>from_jid: Optional custom sender JID.

<pre>
  The default is &lt;appid&gt;@appspot.com. Custom JIDs can be of the form
  &lt;anything&gt;@&lt;appid&gt;.appspotchat.com.
</pre>
</li>
</ul>

                </div>
                
                
                
                
                <div class="sourcecode">
                    <p class="source-link">
                        Source: <a href="javascript:toggleSource('M000199_source')" id="l_M000199_source">show</a>
                        
                    </p>
                    <div id="M000199_source" class="dyn-source">
                        <pre><span class="ruby-comment cmt"># File lib/appengine-apis/xmpp.rb, line 204</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_invitation</span>(<span class="ruby-identifier">jid</span>, <span class="ruby-identifier">from_jid</span>=<span class="ruby-keyword kw">nil</span>)
        <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Jabber ID cannot be nil'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jid</span>.<span class="ruby-identifier">nil?</span>
        <span class="ruby-identifier">request</span> = <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">XmppInviteRequest</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">set_jid</span>(<span class="ruby-identifier">jid</span>)
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">set_from_jid</span>(<span class="ruby-identifier">from_jid</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">from_jid</span>

        <span class="ruby-identifier">make_sync_call</span>(<span class="ruby-value str">'SendInvite'</span>, <span class="ruby-identifier">request</span>, <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">XmppInviteResponse</span>)
        <span class="ruby-keyword kw">nil</span>
      <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ApiProxy</span><span class="ruby-operator">::</span><span class="ruby-constant">ApplicationException</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span>.<span class="ruby-identifier">value_of</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">application_error</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">INVALID_JID</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid jabber ID: #{jid}&quot;</span>
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">XMPPError</span>, <span class="ruby-value str">'Unknown error sending invitation to jabber ID: '</span> <span class="ruby-operator">+</span>
              <span class="ruby-identifier">jid</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-keyword kw">end</span></pre>
                    </div>
                </div>
                
            </div>
            
            <div class="method">
                <div class="title">
                    
                    <a name="M000200"></a><b>XMPP.send_message(message)
or
XMPP.send_message(*message_args)
</b>
                    
                </div>
                
                <div class="description">
                  
                  <p>
Send a chat message.
</p>
<p>
Args:
</p>
<ul>
<li>message: A <a href="XMPP/Message.html">Message</a> object to send.

</li>
<li>message_args: Used to create a new <a href="XMPP/Message.html">Message</a>.
See <a href="XMPP/Message.html">Message</a>.new

</li>
</ul>
<p>
Returns an Array Statuses, one for each JID, corresponding to the result of
sending the message to that JID.
</p>

                </div>
                
                
                
                
                <div class="sourcecode">
                    <p class="source-link">
                        Source: <a href="javascript:toggleSource('M000200_source')" id="l_M000200_source">show</a>
                        
                    </p>
                    <div id="M000200_source" class="dyn-source">
                        <pre><span class="ruby-comment cmt"># File lib/appengine-apis/xmpp.rb, line 236</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_message</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Message</span>
          <span class="ruby-identifier">message</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">request</span> = <span class="ruby-identifier">message</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">:to_proto</span>
        <span class="ruby-identifier">response</span> = <span class="ruby-identifier">make_sync_call</span>(<span class="ruby-value str">'SendMessage'</span>, <span class="ruby-identifier">request</span>,
                                  <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">XmppMessageResponse</span>)
        <span class="ruby-identifier">response</span>.<span class="ruby-identifier">status_iterator</span>.<span class="ruby-identifier">to_a</span>
      <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ApiProxy</span><span class="ruby-operator">::</span><span class="ruby-constant">ApplicationException</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-keyword kw">case</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span>.<span class="ruby-identifier">value_of</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">application_error</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">INVALID_JID</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid jabber ID&quot;</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">NO_BODY</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Missing message body&quot;</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">INVALID_XML</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Invalid XML body&quot;</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proto</span><span class="ruby-operator">::</span><span class="ruby-constant">ErrorCode</span><span class="ruby-operator">::</span><span class="ruby-constant">INVALID_TYPE</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid type #{message.type.inspect}&quot;</span>
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">XMPPError</span>, <span class="ruby-value str">'Unknown error sending message'</span>
        <span class="ruby-keyword kw">end</span>
      <span class="ruby-keyword kw">end</span></pre>
                    </div>
                </div>
                
            </div>
            
</div>
    </div>
  </body>
</html>    